﻿using CDSysLDManageProject.BYDTableAdapters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CDSysLDManageProject
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        tbl_LDTaskListTableAdapter ldtask = new tbl_LDTaskListTableAdapter();
        tbl_stageinfoTableAdapter stageinfo = new tbl_stageinfoTableAdapter();
        private void button1_Click(object sender, EventArgs e)
        {

            StaticArg.CheckStatus = "open";
            FormClosedCheck cc = new FormClosedCheck();
            cc.ShowDialog();

            if (StaticArg.CheckStatus != "close")
            {
                return;
            }

            string trayno = tbxtrayno.Text;
            string recipeid = tbxrecipeid.Text;
            short actionid = 120;
            short actiontype = 4;
            short priority = short.Parse(tbxpriority.Text);
            string fromx = tbxfromx.Text.PadLeft(3,'0');
            string froml = tbxfroml.Text.PadLeft(3, '0');
            string fromc = tbxfromc.Text.PadLeft(3, '0');
            string tox = tbxtox.Text.PadLeft(3, '0');
            string tol = tbxtol.Text.PadLeft(3, '0');
            string toc = tbxtoc.Text.PadLeft(3, '0');
            string usr = "test";
            string fromlocation = fromx+ froml+ fromc;
            string tolocation = tox + tol + toc;

            if (priority > 90)
            {
                MessageBox.Show("优先级必须小于90!");
            }

           

            DataTable dtstageinfo = stageinfo.GetReservedStageLocation();
            if (dtstageinfo.Rows.Count > 0)
            {

            }
            else
            {
                MessageBox.Show("请先预约架台在手动生成任务!");
                return;
            }


            try
            {
                ldtask.InsertTask(trayno, recipeid, actionid, actiontype, fromlocation, fromx, froml, fromc, tolocation, tox, tol, toc, priority, null, "m", usr, DateTime.Now, null, null, null,0);
                MessageBox.Show("保存成功");
            }
            catch (Exception)
            {
                lbmsg.Text = "保存任务失败，请检查输入的托盘号是否正确";
                lbmsg.BackColor = Color.Red;
            }
            

        }
    }
}
